home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / OT PAPServerSample / PAPServerSample.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  9.9 KB  |  273 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        PAPServerSample.h
  3.  
  4.     Contains:    headers, defines for the PAPServerSample.c file
  5.  
  6.     Written by: Rich Kubota    
  7.  
  8.     Copyright:    Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/22/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. #ifndef __PAPSERVERSAMPLE__
  25. #define __PAPSERVERSAMPLE__
  26.  
  27.  
  28. #ifndef __CONDITIONALMACROS__
  29. #include <ConditionalMacros.h>
  30. #endif
  31.  
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35.  
  36. #if PRAGMA_ALIGN_SUPPORTED
  37. #pragma options align=mac68k
  38. #endif
  39.  
  40. #if PRAGMA_IMPORT_SUPPORTED
  41. #pragma import on
  42. #endif
  43.  
  44. #include <stdio.h>
  45. #include <Types.h>
  46. #include <Memory.h>
  47. #include <Resources.h>
  48. #include <Events.h>
  49. #include "OpenTransport.h"        // open transport files    
  50. #include "OpenTptAppleTalk.h"    
  51.  
  52. #define SHOW_DEBUG_FLOW        1    // enable display of DebugStr showing program flow
  53.  
  54. #if SHOW_DEBUG_FLOW
  55. #define    DO_DEBUG_LOG        0    // enable a debug log at the beginning
  56. #endif
  57.  
  58. // defines for the STR# resource
  59. #define kServerStrID    1000    // STR# resource ID for the PAP Server Sample strings
  60.  
  61. #define kOTVersion111    0x01118000
  62. #define kOTVersion120    0x01208000
  63.  
  64. enum {
  65.     kServerNBPStrID    = 1,
  66.     kIdleStrID,
  67.     kBusyStrID
  68. };
  69.  
  70. #define kZeroQLen        0
  71. #define kDynamicSocket    0
  72. #define kATPType        3
  73. #define TIMEOUT            25         // seconds
  74. #define kMaxHandoffEPs    5        // maximum number of handoff endpoints supported by this sample
  75.  
  76. #define kDITop            0x0050        /* kTopLeft - for positioning the Disk
  77.                                                Initialization dialogs. */
  78. #define kDILeft            0x0070
  79.  
  80. #define kNumBuffers        25        // initial number of packet buffers to allocate
  81. #define kUserByteSize    4
  82. #define    kPAPDataSize    32768    // if we can, collect 16K of data at a time        
  83.  
  84. // defines for gFlags bits
  85. #define OTActiveFlag        0
  86. #define    dumpPktsFlag        1
  87. #define BufsInitdFlag        4
  88. #define InBackGndFlag        5
  89. #define BuffsHeldFlag        6
  90. #define CheckOptFlag        7
  91. #define StatusBusyFlag        8
  92. #define StatusIdleFlag        9
  93.  
  94. // flags macros for setting, testing and clearing the gFlag bits
  95. #define SetOTActiveFlag(flags)        ((flags) |= 1 << OTActiveFlag)
  96. #define ClrOTActiveFlag(flags)        ((flags) &= (-1 ^ (1 << OTActiveFlag)))
  97. #define TstOTActiveFlag(flags)        (((flags) & (1 << OTActiveFlag)) != 0)
  98.  
  99. #define SetdumpPktsFlag(flags)        ((flags) |= 1 << dumpPktsFlag)
  100. #define ClrdumpPktsFlag(flags)        ((flags) &= (-1 ^ (1 << dumpPktsFlag)))
  101. #define TstdumpPktsFlag(flags)        (((flags) & (1 << dumpPktsFlag)) != 0)
  102.  
  103. #define SetBufsInitdFlag(flags)        ((flags) |= 1 << BufsInitdFlag)
  104. #define ClrBufsInitdFlag(flags)        ((flags) &= (-1 ^ (1 << BufsInitdFlag)))
  105. #define TstBufsInitdFlag(flags)        (((flags) & (1 << BufsInitdFlag)) != 0)
  106.  
  107. #define SetInBackGndFlag(flags)        ((flags) |= 1 << InBackGndFlag)
  108. #define ClrInBackGndFlag(flags)        ((flags) &= (-1 ^ (1 << InBackGndFlag)))
  109. #define TstInBackGndFlag(flags)        (((flags) & (1 << InBackGndFlag)) != 0)
  110.  
  111. #define SetBuffsHeldFlag(flags)        ((flags) |= 1 << BuffsHeldFlag)
  112. #define ClrBuffsHeldFlag(flags)        ((flags) &= (-1 ^ (1 << BuffsHeldFlag)))
  113. #define TstBuffsHeldFlag(flags)        (((flags) & (1 << BuffsHeldFlag)) != 0)
  114.  
  115. #define SetCheckOptFlag(flags)        ((flags) |= 1 << CheckOptFlag)
  116. #define ClrCheckOptFlag(flags)        ((flags) &= (-1 ^ (1 << CheckOptFlag)))
  117. #define TstCheckOptFlag(flags)        (((flags) & (1 << CheckOptFlag)) != 0)
  118.  
  119. #define SetStatusBusyFlag(flags)    ((flags) |= 1 << StatusBusyFlag)
  120. #define ClrStatusBusyFlag(flags)    ((flags) &= (-1 ^ (1 << StatusBusyFlag)))
  121. #define TstStatusBusyFlag(flags)    (((flags) & (1 << StatusBusyFlag)) != 0)
  122.  
  123. #define SetStatusIdleFlag(flags)    ((flags) |= 1 << StatusIdleFlag)
  124. #define ClrStatusIdleFlag(flags)    ((flags) &= (-1 ^ (1 << StatusIdleFlag)))
  125. #define TstStatusIdleFlag(flags)    (((flags) & (1 << StatusIdleFlag)) != 0)
  126.  
  127. // defines for the semaphore bits
  128. #define kInListenLoop        0        // this bit used with OTAtomicSetBit to control re-entrancy into the DoListenAccept procedure
  129. #define kInRcvDataFlag        1        // used with OTAtomic calls to check whether in DoReceive call
  130.  
  131. // defines for flags bits
  132. #define EPActiveFlag        0        // indicates that the endpoint is active
  133. #define EPBoundFlag            1        // indicates the endpoint is bound
  134. #define EPListenFlag        2        // indicates that the endpoint has processed a listen request
  135. #define EPBusyFlag            3        // used with handoff endpoint to indicate it has accepted 
  136.                                     // a handoff endpoint
  137. #define ListenerSavedFlag    4        // a listener has been identified and saved locally
  138. #define PassconFlag            6        // the passive connection has completed
  139. #define EOMOnFlag            7        // EOM option enabled
  140. #define ListenPendFlag        10
  141. #define AcceptPendFlag        11
  142. #define    TempFileFlag        12        // indicates that a temp file has been opened for data to this endpoint
  143. #define InPSQueryFlag        13        // indicates that the endpoint is currently processing a PS query
  144. #define HasDataFlag            14        // indicates that there is more to read for this endpoint
  145. #define OrdDisconFlag        15        // indicates that the server received an orderly discon event
  146.  
  147. // flags macros for setting, testing and clearing the flag bits
  148. #define SetEPActiveFlag(flags)        ((flags) |= 1 << EPActiveFlag)
  149. #define ClrEPActiveFlag(flags)        ((flags) &= (-1 ^ (1 << EPActiveFlag)))
  150. #define TstEPActiveFlag(flags)        (((flags) & (1 << EPActiveFlag)) != 0)
  151.  
  152. #define SetEPBoundFlag(flags)        ((flags) |= 1 << EPBoundFlag)
  153. #define ClrEPBoundFlag(flags)        ((flags) &= (-1 ^ (1 << EPBoundFlag)))
  154. #define TstEPBoundFlag(flags)        (((flags) & (1 << EPBoundFlag)) != 0)
  155.  
  156. #define SetEPListenFlag(flags)        ((flags) |= 1 << EPListenFlag)
  157. #define ClrEPListenFlag(flags)        ((flags) &= (-1 ^ (1 << EPListenFlag)))
  158. #define TstEPListenFlag(flags)        (((flags) & (1 << EPListenFlag)) != 0)
  159.  
  160. #define SetEPBusyFlag(flags)        ((flags) |= 1 << EPBusyFlag)
  161. #define ClrEPBusyFlag(flags)        ((flags) &= (-1 ^ (1 << EPBusyFlag)))
  162. #define TstEPBusyFlag(flags)        (((flags) & (1 << EPBusyFlag)) != 0)
  163.  
  164. #define SetListenerSavedFlag(flags)    ((flags) |= 1 << ListenerSavedFlag)
  165. #define ClrListenerSavedFlag(flags)    ((flags) &= (-1 ^ (1 << ListenerSavedFlag)))
  166. #define TstListenerSavedFlag(flags)    (((flags) & (1 << ListenerSavedFlag)) != 0)
  167.  
  168. #define SetPassconFlag(flags)        ((flags) |= 1 << PassconFlag)
  169. #define ClrPassconFlag(flags)        ((flags) &= (-1 ^ (1 << PassconFlag)))
  170. #define TstPassconFlag(flags)        (((flags) & (1 << PassconFlag)) != 0)
  171.  
  172. #define SetEOMOnFlag(flags)            ((flags) |= 1 << EOMOnFlag)
  173. #define ClrEOMOnFlag(flags)            ((flags) &= (-1 ^ (1 << EOMOnFlag)))
  174. #define TstEOMOnFlag(flags)            (((flags) & (1 << EOMOnFlag)) != 0)
  175.  
  176. #define SetListenPendFlag(flags)    ((flags) |= 1 << ListenPendFlag)
  177. #define ClrListenPendFlag(flags)    ((flags) &= (-1 ^ (1 << ListenPendFlag)))
  178. #define TstListenPendFlag(flags)    (((flags) & (1 << ListenPendFlag)) != 0)
  179.  
  180. #define SetAcceptPendFlag(flags)    ((flags) |= 1 << AcceptPendFlag)
  181. #define ClrAcceptPendFlag(flags)    ((flags) &= (-1 ^ (1 << AcceptPendFlag)))
  182. #define TstAcceptPendFlag(flags)    (((flags) & (1 << AcceptPendFlag)) != 0)
  183.  
  184. #define SetTempFileFlag(flags)        ((flags) |= 1 << TempFileFlag)
  185. #define ClrTempFileFlag(flags)        ((flags) &= (-1 ^ (1 << TempFileFlag)))
  186. #define TstTempFileFlag(flags)        (((flags) & (1 << TempFileFlag)) != 0)
  187.  
  188. #define SetInPSQueryFlag(flags)        ((flags) |= 1 << InPSQueryFlag)
  189. #define ClrInPSQueryFlag(flags)        ((flags) &= (-1 ^ (1 << InPSQueryFlag)))
  190. #define TstInPSQueryFlag(flags)        (((flags) & (1 << InPSQueryFlag)) != 0)
  191.  
  192. #define SetHasDataFlag(flags)        ((flags) |= 1 << HasDataFlag)
  193. #define ClrHasDataFlag(flags)        ((flags) &= (-1 ^ (1 << HasDataFlag)))
  194. #define TstHasDataFlag(flags)        (((flags) & (1 << HasDataFlag)) != 0)
  195.  
  196. #define SetOrdDisconFlag(flags)        ((flags) |= 1 << OrdDisconFlag)
  197. #define ClrOrdDisconFlag(flags)        ((flags) &= (-1 ^ (1 << OrdDisconFlag)))
  198. #define TstOrdDisconFlag(flags)        (((flags) & (1 << OrdDisconFlag)) != 0)
  199.  
  200.  
  201. enum {
  202.     kLookingForEndStr = 1,
  203.     kLookingForQueryStr,
  204.     kLookingForDefaultResponse,
  205.     kLookingForEOFStr
  206. };
  207.  
  208. enum {
  209.     kSetBusyStr = 1,
  210.     kSetIdleStr,
  211.     kAcceptOption,
  212.     kDeclineOption,
  213.     kQuitTest
  214. };    
  215.  
  216.  
  217. /*******************************************************************************
  218. ** Structures
  219. ********************************************************************************/
  220. typedef struct MyEndpointRef MyEndpointRef;
  221.  
  222. typedef struct 
  223. {
  224.         OTLink        fLink;                        // first field standard for OTLink list
  225.         OTFlags        flags;
  226.         MyEndpointRef *theEp;                    // save the endpoint ref associated with the endpoint
  227.         UInt32        lastPos;                    // last scanned position in the buffer
  228.         UInt32        numBytes;                    // numBytes in this packet
  229.         OTTimeStamp    timeStamp;                    // timestamp of this packet
  230.         UInt8        data[kPAPDataSize];            // data bytes of packet
  231. } PacketBuffer;
  232.  
  233. typedef PacketBuffer *PacketPtr;
  234.  
  235. struct MyEndpointRef
  236. {
  237.     EndpointRef        ep;
  238.     UInt32            flags;
  239.     OTLIFO            *usedQ;                    // ptr to incoming packet queue for this connection
  240.     PacketPtr        prevPtr;                // used while processing a postscript
  241.                                             // query where we have to save the previous packet
  242.                                             // in order to complete processing of queries.
  243.     OTTimeStamp        timeDataIn;                // timestamp of first incoming packet
  244.     OTTimeStamp     timeDataEnd;            // timestamp of last incoming packet
  245.     OTTimeStamp        timerDog;                // timestamp of most recent packet
  246.  
  247.     UInt32            numBytesIn;                // number of bytes received for a connection
  248.     UInt16            psState;                // state while processing a postscript query
  249.     short            fRefNum;                // file ref num of temp file associated
  250.                                             //    with this endpoint
  251.     UInt8            semaphore;
  252.     UInt8            dummy;
  253. };
  254.  
  255.  
  256. // Prototypes
  257. extern void DoValueBreak(long value, const char* message);
  258.  
  259.  
  260. #if PRAGMA_IMPORT_SUPPORTED
  261. #pragma import off
  262. #endif
  263.  
  264. #if PRAGMA_ALIGN_SUPPORTED
  265. #pragma options align=reset
  266. #endif
  267.  
  268. #ifdef __cplusplus
  269. }
  270. #endif
  271.  
  272. #endif /* __PAPSERVERSAMPLE__ */
  273.